package xyz.xiangyushui.controller.membership.reserveDesserts;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import xyz.xiangyushui.dao.user.member.CommodityReservableDao;

/**
 * Servlet implementation class DessertsReservable
 */
@WebServlet("/member/reserve")
public class DessertsReservable extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CommodityReservableDao crd;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DessertsReservable() {
        super();
        crd=new CommodityReservableDao();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String date=request.getParameter("date");
		String store=request.getParameter("store");
		long dateLong = 0;
		if("".equals(date)||"".equals(store)){
			
		}else{
			try {
				dateLong=new SimpleDateFormat("yyyy-MM-dd").parse(date).getTime();
			} catch (ParseException e) {
				e.printStackTrace();
			}
			String[] id_name=store.split("-");
			String planId=dateLong+"_"+Integer.parseInt(id_name[0]);
			request.setAttribute("date_storeId", planId);
			request.setAttribute("commodities", crd.getCommodityReservable(planId));
		}
			request.getRequestDispatcher("/member").forward(request, response);
		}
	
	}
